class Solution:
    def minSwapsCouples(self, row: List[int]) -> int:
        length=len(row)
        docks=[0]*length
        before=True
        for i in range(length):
            if before:
                docks[row[i]]=row[i+1]
            else:
                docks[row[i]]=row[i-1]
            before=not before
        count=0
        for i in range(0,length,2):
            if docks[i]//2!=i//2:
                if docks[i]%2==0:
                    target=docks[i]+1
                else:
                    target=docks[i]-1
                if docks[target]//2==i//2:
                    count+=1
                    docks[target]=docks[i]
                    docks[docks[i]]=target
                else:
                    docks[docks[i+1]]=docks[i]
                    docks[docks[i]]=docks[i+1]
                    docks[i+1]=i
                    count+=1
        return count


'''
执行用时：
36 ms
, 在所有 Python3 提交中击败了
93.97%
的用户
内存消耗：
14.9 MB
, 在所有 Python3 提交中击败了
11.21%
的用户
'''